package com.boost.tjvm.invoke;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

/**
 * 经过验证这个例子 在jdk 11 中是错误的
 *
 */
public class CallAncestorsMethod {

    class GrandFather{
        void thinking(){
            System.out.println("i am grandfather");
        }
    }


    class Father extends GrandFather{
        void thinking(){
            System.out.println("i am father");
        }
    }

    class Son extends Father{
        void thinking(){
            try {
                System.out.println("i am son");
                MethodType mt=MethodType.methodType(void.class);
                MethodHandle thinking = MethodHandles.lookup().findSpecial(GrandFather.class, "thinking", mt, super.getClass());
                thinking.invoke(this);
            }catch (Throwable e){

            }

        }
    }

    public static void main(String[] args) throws Throwable {
        (new CallAncestorsMethod().new Son()).thinking();
    }
}
